package com.twu.biblioteca;

import java.io.PrintStream;
import java.util.HashMap;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Thoughtworker
 * Date: 8/23/13
 * Time: 10:47 AM
 * To change this template use File | Settings | File Templates.
 */
public class UserGetter implements Command {
    private Output output;
    private HashMap<String,User> users;
    private User privateUser;

    public UserGetter(HashMap<String, User> users, Output output) {
        this.users = users;
        this.output = output;


    }

    public String getCommandName()
    {
        return "Check Membership";
    }

    public void setUser(User user)
    {
        this.privateUser = user;
    }

    public User verifyUserExists(String username) {
        User user = users.get(username);

        return user;
    }

    public boolean verifyUserAndPassword(User user, String password) {
        if (user == null)
        {
            output.printNotLoggedIn();
            return false;
        }
        if (user.getPassword().equals(password))
        {
            output.printLoggedIn();
            return true;
        }
        else{
            output.printNotLoggedIn();
            return false;
        }
    }

    public void execute(int order, boolean canExecute) {
        if(canExecute)
        {
            output.printUserDetails(this.privateUser);
        }
        output.printPleaseTalkToLibrarianMessage();

    }


}
